package com.kotlin.heimaplayer.ui.fragment

import android.view.View
import com.kotlin.heimaplayer.R
import com.kotlin.heimaplayer.adapter.MvPagerAdapter
import com.kotlin.heimaplayer.base.BaseFragment
import com.kotlin.heimaplayer.model.CommonResultBean
import com.kotlin.heimaplayer.model.MvAreaBean
import com.kotlin.heimaplayer.presenter.impl.MvPresenterImpl
import com.kotlin.heimaplayer.view.MvView
import kotlinx.android.synthetic.main.fragment_mv.*

class MvFragment : BaseFragment(), MvView {
    override fun onError(msg: String?) {
        myToast("加载区域数据失败")
    }

    override fun onSuccess(result: CommonResultBean<MvAreaBean>) {
        println(result.data.sub)
        // 在fragment中管理fragment需要使用childFragmentManager
        val adapter = MvPagerAdapter(context,result,childFragmentManager)
        viewPager.adapter = adapter
        tabLayout.setupWithViewPager(viewPager)
    }

    val presenter by lazy { MvPresenterImpl(this) }

    override fun initView(): View? {
        return View.inflate(context, R.layout.fragment_mv,null)
    }

    override fun initListener() {
        super.initListener()
    }

    override fun initData() {
        // 加载分类数据
        presenter.loadDatas()
    }

}